#1 Uva10041 - Vito's family
#include <bits/stdc++.h>
using namespace std;
int main() {
int t,r,x;
cin>>t;
while(t--){
cin>>r;
vector <int> v;
for(int i=0;i<r;i++){
cin>>x;
v.push_back(x);
}
sort(v.begin(),v.end());
int mid=v[v.size()/2],ans=0;
for(int i=0;i<v.size();i++)ans+=abs(mid-v[i]);
cout<<ans<<endl;
}
}